package com.kcwl.carrier.domain.service;

import com.kcwl.carrier.domain.entity.VehicleTrailerCondition;
import com.kcwl.carrier.domain.entity.VehicleTrailerInfo;
import com.kcwl.carrier.domain.repository.IVehicleInfoRepository;
import com.kcwl.carrier.domain.repository.IVehicleTrailerRepository;
import com.kcwl.carrier.infrastructure.repository.po.VehicleTrailerPO;
import com.kcwl.carrier.interfaces.dto.VehicleTrailerInfoDTO;
import com.kcwl.carrier.interfaces.dto.VehicleTrailerListDTO;
import com.kcwl.carrier.interfaces.query.PlateNumberQuery;
import com.kcwl.carrier.interfaces.query.VehicleTrailerQuery;
import com.kcwl.ddd.infrastructure.utils.KcPageConverter;
import com.kcwl.ddd.interfaces.dto.PageInfoDTO;
import com.kcwl.framework.utils.KcBeanConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class VehicleTrailerDomainService {

    @Resource
    private IVehicleTrailerRepository vehicleTrailerRepository;
    @Resource
    private IVehicleInfoRepository vehicleInfoRepository;

    public List<VehicleTrailerInfo> getByIds(List<Long> ids) {
        return vehicleTrailerRepository.getByIds(ids);
    }

    public void save(VehicleTrailerPO trailerPO) {
        vehicleTrailerRepository.save(trailerPO);
    }

    public List<VehicleTrailerInfo> getList(VehicleTrailerCondition condition) {
        return vehicleTrailerRepository.getList(condition);
    }

    public void updateById(VehicleTrailerInfo vehicleTrailer) {
        vehicleTrailerRepository.updateById(vehicleTrailer);
    }

    public VehicleTrailerInfo getById(Long trailerId) {
        return KcBeanConverter.toBean(vehicleTrailerRepository.getById(trailerId), VehicleTrailerInfo.class);
    }

    public void updateTrailer(VehicleTrailerInfo info) {
        vehicleTrailerRepository.updateById(info);
    }

    public PageInfoDTO<VehicleTrailerInfoDTO> getTrailerList(PlateNumberQuery query) {
        return KcPageConverter.toPageInfoDTO(vehicleTrailerRepository.getTrailerList(query), VehicleTrailerInfoDTO.class);
    }

    public PageInfoDTO<VehicleTrailerListDTO> queryVehicleTrailerPage(VehicleTrailerQuery query) {
        return KcPageConverter.toPageInfoDTO(vehicleTrailerRepository.queryVehicleTrailerPage(query), VehicleTrailerListDTO.class);
    }

    public VehicleTrailerInfo getTrailerDetail(Long id) {
        return vehicleTrailerRepository.getTrailerDetail(id);
    }
}
